/**
 * @author HanleyTang
 * @date 2018-12-14
 */
public class ThlwsDemo {

    private static  final  ThreadLocal<Long> threadLocal = new ThreadLocal<Long>(){
        @Override
        protected Long initialValue() {
            return 0L;
        }


    };


    static class MyThread extends Thread{

        long value;

        public MyThread(long value) {
            this.value = value;
        }

        @Override
        public void run() {
            threadLocal.set(value);
            System.out.println("currentThread="+Thread.currentThread().getName()+",currentValue="+threadLocal.get());
        }
    }


    public static void main(String[] args) {

        for (int i=1;i<6; i++){
            MyThread myThread = new MyThread(i);
            myThread.setName("thread-"+i);
            myThread.start();

        }

    }

}
